package application;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Project Statistics and Characteristics for a specific project according to
 * the COCOMO II model.
 */
public class Project {
	private HashMap<String, Double> dataCharacteristics;
	private ArrayList<String> characteristics;

	/** Actual effort */
	private double actualEffort;

	private HashMap<String, Double> minValue;
	private HashMap<String, Double> maxValue;

	public Project() {
		dataCharacteristics = new HashMap<String, Double>();
		characteristics = new ArrayList<String>();
	}

	/**
	 * Convenience method @see addEffortMultiplier(EffortMultiplier key,
	 * MultiplierEstimation value)
	 * 
	 * @param key
	 * @param value
	 * @return
	 */

	public void addCharacteristic(String key, Double value) {
		dataCharacteristics.put(key, value);
		characteristics.add(key);
	}

	public Double getCharacteristicValue(String key) {
		return dataCharacteristics.get(key);
	}

	/**
	 * Is needed to be called before using the method: "compareTo"
	 * 
	 * @param deltaValue
	 */
	public void setDeltaValue(HashMap<String, Double> minValue,
			HashMap<String, Double> maxValue) {
		this.maxValue = maxValue;
		this.minValue = minValue;

	}

	/**
	 * @param p Compares the current project with the project p
	 * 
	 * @return an Integer between 0 and 100
	 */
	public int compareWith(Project p) {
		Double temp = 0.0;
		Double sum = 0.0;
		int count = 0;
		for (String s : characteristics) {
			if(!s.equalsIgnoreCase("effort")){
				temp = p.getCharacteristicValue(s);
				if (temp != null) {
					sum += Math.abs(this.getCharacteristicValue(s) - temp)
							/ (maxValue.get(s) - minValue.get(s));
					count++;
				}
			}
		}
		sum = sum / count;

		return (int) ((1.0 - Math.sqrt(sum)) * 100);
	}

	public String getCharacteristic(int i) {
		return characteristics.get(i);
	}

}
